import java.util.*;
public class Main2 {
    static class Trans implements Comparable<Trans>{
      int start,end,money;
      Trans(int start,int end,int money){
          this.end=end;
          this.money=money;
          this.start=start;
      }
        @Override
        public int compareTo(Trans o) {
            return this.end-o.end;
        }
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M=scanner.nextInt();
        Trans[] trans = new Trans[M];
        for(int i=0;i<M;i++){
            trans[i]=new Trans(scanner.nextInt(),scanner.nextInt(),scanner.nextInt());
        }
        Arrays.sort(trans);
        int[] dp=new int[M];
        dp[0]=trans[0].money;
        for(int i=1;i<M;i++){
            int low=0,high=i-1;
            while(low<=high){
                int mid=(high+low)/2;
                if(trans[mid].end>=trans[i].start){
                    high=mid-1;
                }else{
                    low=mid+1;
                }
            }
                if(high>=0){
                    dp[i]=Math.max(dp[i-1],dp[high]+trans[i].money);
                }
                else{
                    dp[i]=Math.max(dp[i-1],trans[i].money);
                }
        }
        System.out.println(dp[M-1]);
   }
}
